// 使用ES2017中的async和await

export default async () => {
  function ajax(url) {
    return new Promise(function (resolver, reject) {
      var xhr = new XMLHttpRequest();
      xhr.open("GET", url);
      xhr.responseType = "json";
      xhr.onload = function () {
        if (this.status === 200) {
          resolver(this.response);
        } else {
          reject(new Error(this.statusText))
        }
      };

      xhr.send();
    })
  }


  let users = await ajax("/api/users.json");
  console.log(users);
  let request = await ajax("/api/posts.json");
  console.log(request);
}